package opl.ui;

import opl.common.ConfigurationSettings;
import opl.services.NotificationService;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceManager;

public class PreferenceActivity extends android.preference.PreferenceActivity
		implements OnSharedPreferenceChangeListener {

	private SharedPreferences _sp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.opl_preference);
		_sp = PreferenceManager.getDefaultSharedPreferences(this);
		_sp.registerOnSharedPreferenceChangeListener(this);
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
			String key) {
		// TODO: Have operations to be done when configuration changes.
		if (key.equalsIgnoreCase(ConfigurationSettings.SYNC_INTERVAL)) {
			int value = Integer.parseInt(ConfigurationSettings.getValue(
					ConfigurationSettings.SYNC_INTERVAL, this));
			Intent intService = new Intent(this, NotificationService.class);
			intService.putExtra(ConfigurationSettings.SYNC_INTERVAL, value);
			stopService(intService);
			startService(intService);
		}
	}

}
